package py.edu.ucom.cadira.game.event.war;

import org.jdom.Document;
import org.jdom.Element;
import py.edu.ucom.cadira.game.war.Board;
import py.edu.ucom.cadira.game.war.WarUser;

/**
 * 
 * @author largonet
 * 
 */
public class EndGameEvent extends WarGameEvent {

    private WarUser user;
    private Board board;
    public EndGameEvent() {
		
	}
	/**
     * @return Returns the board.
     */
    
    public Board getBoard() {
        return board;
    }
    /**
     * @param board The board to set.
     */
    public void setBoard(Board board) {
        this.board = board;
    }
    /**
     * @param user The user to set.
     */
    public void setUser(WarUser user) {
        this.user = user;
    }
    public EndGameEvent(WarUser user, Board table) {
    	
    }
    public Board getTable() {
        return board;
    }
    public WarUser getUser() {
        return user;
    }
    /* (non-Javadoc)
     * @see py.edu.ucom.cadira.game.event.GameEvent#fromXML(org.jdom.Document)
     */
    @Override
    public void fromXML(Document xml) {
        Element root = xml.getRootElement();
        Element endGameNode = root.getChild("endGame");
        Element userNode = endGameNode.getChild("usuario");
        user.fromXml(userNode);
        
        Element tableNode = endGameNode.getChild("tablero");
        board.fromXml(tableNode);
    }
    /* (non-Javadoc)
     * @see py.edu.ucom.cadira.game.event.GameEvent#toXML(org.jdom.Element)
     */
    @Override
    public void toXML(Element root) {
        Element endGameNode = new Element("endGame");
        Element userNode = user.toXml();
        Element tableNode = new Element("tablero");
        Element boardNode = board.toXml(tableNode);
        endGameNode.addContent(userNode);
        endGameNode.addContent(boardNode);
        
        root.addContent(endGameNode);
    }
    @Override
	public boolean equals(Object obj) {
		if (!(obj instanceof EndGameEvent)) {
			return false;
		}
		EndGameEvent otherObj = (EndGameEvent) obj;
		if (otherObj.getUser().equals(getUser())) {
			return true;
		}
		return false;
	}
}
